'''
@auther tianxiaoxi  
@file test02_user by
@time 2021/12/23 9:46
'''
import unittest
from api.user import UserAPI
from utils import common_assert


class TestUser(unittest.TestCase):
    user_id = None

    def setUp(self):
        self.user_api = UserAPI()

    def tearDown(self):
        pass

    def test01_user_add(self):
        # 添加员工
        response = self.user_api.user_add({
            "username": "tsd1xi1",
            "mobile": "14333114423",
            "workNumber": "3412"
        })

        TestUser.user_id = response.json().get("data").get("id")

        # 断言
        common_assert(self, response)

    def test02_user_update(self):
        # 修改员工
        print(self.user_id)
        response = self.user_api.user_update(target=self.user_id, json={
            "password": "123456"
        })

        print("修改员工", response.json())
        # user_id = response.json().get("data").get("id")

        # 断言
        common_assert(self, response)
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("成功", response.json().get("message"))

    def test03_user_select(self):
        print(self.user_id)
        # 查询员工
        response = self.user_api.user_select(self.user_id)
        print("查询员工", response.json())

        # 断言
        common_assert(self, response)

    def test04_user_delete(self):
        # 删除员工
        print(self.user_id)
        response = self.user_api.user_delete(self.user_id)
        print("删除员工", response.json())

        # 断言
        common_assert(self, response)
